# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from .raw_and_code_block import RawAndCodeBlock

class RawText(RawAndCodeBlock):
    '''
    Raw-Text parser
    '''
    def __init__(self, content):
        super(RawText, self).__init__(content, "'", 'raw_text')
        self.html_escape_table = {
            '&': '&amp;',
            '"': '&quot;',
            "'": '&apos;',
            '>': '&gt;',
            '<': '&lt;'
        }

    def _toHtml(self, content):
        return '<pre class="rmk-raw-text">' + self._escape(content) + '</pre>'

    def _escape(self, content):
        return ''.join(self.html_escape_table.get(ch, ch) for ch in content)

    def _unescape(self, content):
        for _k in self.html_escape_table:
            content = content.replace(self.html_escape_table[_k], _k)
        return content